package com.cskaoyan.controller.admin.promotecontroller;


import com.cskaoyan.bean.promotebean.Ad;
import com.cskaoyan.bo.promoteBO.AdUpdateBO;
import com.cskaoyan.service.promoteservice.AdService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.promotevo.AdCreateVO;
import com.cskaoyan.vo.promotevo.AdListVO;
import com.cskaoyan.vo.promotevo.AdUpdateVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;

@RestController
@RequestMapping("admin/ad")
public class  AdController  {
    @Autowired
    AdService adService;
    @RequiresPermissions("admin:ad:list")
    @RequestMapping("list")
    public BaseRespVo list(Integer page, Integer limit,String name,String content, String sort, String order)
    {
        AdListVO adListVO = adService.queryAdAll(page,limit,name,content,sort,order);

        return BaseRespVo.ok(adListVO);

    }




    @RequiresPermissions("admin:ad:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Ad ad){

        AdCreateVO adCreateVO = adService.insert(ad);

        return BaseRespVo.ok(adCreateVO);
    }

    @RequiresPermissions("admin:ad:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody AdUpdateBO ad) throws ParseException {

        AdUpdateVO adUpdateVO = adService.update(ad);

        return BaseRespVo.ok(adUpdateVO);

    }

    @RequiresPermissions("admin:ad:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){

        Object id = map.get("id");

        adService.delete((Integer) id);

        return BaseRespVo.ok();
    }
}
